<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="referrer" content="no-referrer" />
    <title>模型对象</title>
    <style>
        body {
            position: absolute;
            margin: 0;
            width: 100%;
            height: 100%;
        }

        #mapContainer {
            left: 0px;
            top: 0px;
            width: 100%;
            height: 100%;
            float: left;
        }
    </style>
</head>

<body>

    <div id="mapContainer" style="position: relative;">
    </div>

</body>
<script src=""></script>
<script src='/GiswayEngine.js'></script>
<script type="text/javascript">
    var model;
    window.app = new GE.App('mapContainer', {
        position: [122.00151626214978, 40.71106690828059, 10000],
        lookAt: [122.00151626214978, 40.71106690828059, 0],
        cameraScrollSpeed: 15,
        minZoom: 3,
        maxZoom: 21,
        ambientLightIntensity: 5,
        ambientLightType: 'hemiSphere',
        useCarpet: true,
        maxSlopeAngle: 75, //地图最大倾斜角度
        background: "Sky", //"Fog", //
        useDefaultTexture: true, //是否使用瓦片默认纹理
        // extraStep: 4, //额外加载瓦片的步长
        baseLayer: [
            // {
            //     url: ' https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
            //     readableUrl: true,
            //     tileType: 'image',
            // },
        ]
    });
    // 
    // loadModel('http://localhost:9000/examples/resources/3dtiles/test/3dtiles/model/JFKJ0313_SM_DaoLu01.fbx', 'fbx');
    // loadModel('http://localhost:9000/examples/resources/fbx/dianchi3.FBX', 'fbx');
    // loadModel('http://localhost:9000/examples/resources/gltf/Box.gltf', 'gltf');//
    loadModel('http://localhost:9000/examples/resources/obj/水面/水面.obj', 'obj');
    // loadModel('http://localhost:9000/examples/resources/obj/LDW_L15.obj', 'obj');
    // loadModel('http://localhost:9000/examples/resources/fbx/SM_GuanDao3857.fbx', 'fbx');
    // loadModel('http://localhost:9000/examples/resources/obj/syobj/1_____0.obj', 'obj', 'http://localhost:9000/examples/resources/obj/syobj/1____.mtl');
    // btn();
    app.openStats();
    app.on('Click', function (e) {
        console.log(e)
    });
    function loadModel(url, type, extraUrl) {
        model = new GE.OverLay({
            type: type,
            // url: 'http://localhost:9000/examples/resources/fbx/xqazm.fbx',
            url: url,
            mtlUrl: extraUrl,
            // url: 'http://localhost:9000/examples/resources/fbx/ceshi1.FBX',
            // url:'http://192.168.2.43:9000/examples/resources/fbx/box.gltf',
            position: [122.00151626214978, 40.71106690828059, 10.2],
            // changeEmissive: true,
            // gltfUpAxis: 'Y',
            gltfUpAxis: 'Z',
            // scale: [150, 150, 150],
            // rotation: [45, 0, 0],
            success: function (fbxParent) {
                
                let waterOptions = {
                    // color: '#1E90FF', //'#1E90FF', //水面颜色，fffff为透明色
                    // scale: 0.5, //水纹大小
                    // reflectivity: 0,//0.0058,//0.65,// 0.002, //反射度【0-1】
                    // flowX: 0.8, //X方向水流比例（用于控制水的流动方向）【0-1】
                    // flowY: 0.8, //Y方向水流比例（用于控制水的流动方向）【0-1】
                    // flowSpeed: 0.02,
                    // textureWidth: 1024/5,
                    // textureHeight: 1024/5,

                    color: '#1E90FF', //水面颜色，fffff为透明色
                    scale: 0.4, //水纹大小
                    reflectivity: 0.02, //反射度【0-1】
                    flowX: 1, //X方向水流比例（用于控制水的流动方向）【0-1】
                    flowY: 1, //Y方向水流比例（用于控制水的流动方向）【0-1】
                    // flowSpeed: 0.08,
                    refractMap: 'http://localhost:9000/examples/resources/images/water_refract.png',

                    // normalMap0: 'http://localhost:9000/examples/resources/images/Water_1_M_Normal.jpg',
                    // normalMap1: 'http://localhost:9000/examples/resources/images/Water_2_M_Normal.jpg',
                };
                GE.WaterUtilty.setWater(fbxParent, waterOptions);
                return;

                setTimeout(btn, 300);

                traverseMeshes(model, function(mesh){
                   if(mesh.material.length > 1){
                        mesh.material.forEach(element => {
                            // setEmmisive(element);
                            element.side = 2;
                            if(element.opacity != 0){
                                element.transparent = true;
                                element.needsUpdate = true;
                            }
                           
                        });
                   }else{
                        // setEmmisive(mesh.material);
                        mesh.material.side = 2;
                        if(mesh.material.opacity != 0){
                            mesh.material.transparent = true;
                            mesh.material.needsUpdate = true;
                        }
                   }
                });
            }
        })
        app.add(model);

        window.model = model;
    }

    function traverseMeshes(mesh, callback) {
        // 对当前mesh执行回调
        if (mesh.type == 'Mesh') {
            callback(mesh);
        }
        // 遍历子节点
        mesh.children.forEach(child => {
            if (child.isObject3D) {
                traverseMeshes(child, callback);
            }
        });
    }

    function setEmmisive(material) {
        if (!material.emissive) {
            return;
        }
        material.emissive.set(1, 1, 1);
        material.emissiveIntensity = 1;
        material.emissiveMap = material.map;
    }

    function btn() {
        let button = new GE.Button('模型显隐', function () {
            model.visible = !model.visible;
        });
        app.ui.add(button);
        window.button = button;

        let button2 = new GE.Button('模型右移10米', function () {
            model.position.x += 10;
        });
        app.ui.add(button2);

        let button3 = new GE.Button('获取模型详细信息', function () {
            let info = model.getModelInfo();
            alert(JSON.stringify(info));
            console.log(info);
        });
        app.ui.add(button3);


    }
</script>

</html>